package config

import (
	"github.com/BurntSushi/toml"
	"os"
	"sync"
)

var (
	instance *config
	once     sync.Once
)

func Instance() *config {
	once.Do(func() {
		var conf config
		path, _ := os.Getwd()
		filePath := path + "/config/config.toml"
		if _, err := toml.DecodeFile(filePath, &conf); err != nil {
			return
		}
		instance = &conf
	})

	return instance
}

type config struct {
	Database database
	Logger   logger
}

type database struct {
	Host     string `toml:"host"`
	Port     int    `toml:"port"`
	Name     string `toml:"name"`
	Username string `toml:"username"`
	Password string `toml:"password"`
}

type logger struct {
	Path   string
	Level  uint32
	Stdout bool
}
